﻿
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=RYvh3uywSDQYzaoIOiFntTnh"></script>
    <script src="//cdn.bootcss.com/jquery/1.8.3/jquery.min.js"></script>
    <style>
        .leftdiv {
            width: 302px;
            float: left;
        }

        .rightdiv {
            width: 302px;
            float: left;
            height: 355px;
            background-color: #efefef;
        }

        .tj_right ul {
            -webkit-padding-start: 0;
            padding: 0;
            margin: 10px 0 0 10px;
        }

            .tj_right ul li {
                font-size: 11px;
            }

                .tj_right ul li input[type=text] {
                    height: 18px;
                }

        .tj_right_bg table {
            margin-top: 10px;
        }

        #allmap {
            width: 300px;
            height: 300px;
        }

        .tj_right_bg {
            font-size: 11px;
        }

            .tj_right_bg ul {
                margin-top: 0px;
            }

        .pull-right {
            padding-top: 5px;
        }

        .u-page a {
            padding-left: 5px;
        }

        .tj_right ul li {
            list-style: none;
            height: 28px;
            line-height: 28px;
            display: inline-block;
            color: #666;
            font-size: 14px;
        }

        .tj_right ul .li-name {
            width: 24%;
            padding-left: 20px;
        }

        .tj_right ul .li-input {
            width: 62%;
        }

        .tj_right ul .li-input2 {
            width: 26%;
        }

        .tj_right ul .li-input3 {
            width: 26%;
            padding-left: 1px;
        }

        .tj_right div {
            white-space: nowrap;
            float: left;
        }

        .openera {
            cursor: pointer;
            color: #68c500;
        }

        #btnadd {
            background-color: #45b035;
            color: #ffffff;
            border: 0;
            height: 30px;
            width: 100px;
            border-radius: 3px;
            font-size: 14px;
            margin-left: 13px;
        }

        #btnsave, #reset {
            background-color: #45b035;
            color: #ffffff;
            border: 0;
            height: 30px;
            width: 114px;
            border-radius: 3px;
            margin-top: 7px;
            font-size: 14px;
        }

        #btndel {
            background-color: #ccc;
            color: #ffffff;
            border: 0;
            height: 30px;
            width: 60px;
            border-radius: 3px;
        }

        .search-address {
            background-color: #68c500;
            color: #ffffff;
            border: 0;
            width: 80px;
            margin-top: 3px;
            height: 30px;
            border-radius: 3px;
        }

        .maplist {
            width: 100%;
            padding: 10px 5px 0 0;
        }

        .li-bottom-color p {
            margin: 0 10px;
            line-height: 20px;
            height: 20px;
            font-size: 14px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            width: 270px;
        }

        #successTip {
            margin-top: 0px;
            color: #ffffff;
            background-color: #68c500;
            height: 65px;
            padding-left: 10px;
            line-height: 65px;
            position: absolute;
            opacity: 1;
            z-index: 999;
            border-radius: 5px;
            width: 100%;
        }

        .li-bottom-color p span {
            line-height: 20px;
            height: 20px;
            display: inline-block;
            font-size: 14px;
        }

        .li-bottom-color {
            border-bottom: 1px solid #e6e6e6;
            padding: 10px 0px;
            margin: 0 10px;
        }

            .li-bottom-color p .info {
                width: 80%;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }

        .divaddress img {
            margin-bottom: 10px;
        }

        .divaddress {
            border: 1px solid rgb(169, 169, 169);
            background-color: #ffffff;
            margin-top: 5px;
            height: 45px;
        }
    </style>


    <title></title>
</head>
<body style="margin:0px 0 0 0px">
    <input type="hidden" id="addressCount" value="0" />
    <div style="width:302px;height:300px;">
        <div class="maplist" id="maplist" style="display:none">
            <div><label class="checkall" style="display:none"><input type="checkbox" id="allcheck" onclick="checkall();" /><span>全选</span></label> <input type="button" id="btnadd" onclick="addmapdata();" value="添加店铺" /> <input id="btndel" type="button" value="删除" onclick="addressDels();" style="font-size:11px;display:none" />  </div>
            <div class="tj_right_bg">
                <ul class="maplist"></ul>


            </div>
        </div>

        <div class="mapedit" id="mapedit" style="display:block">
            <p style="opacity:0" id="successTip">添加成功！</p>
            <div class="leftdiv"><div id="allmap"></div></div>
            <div class="rightdiv">
                <div class="tj_right">
                    <form action="/map/mapdatasave" method="post">
                        <ul>
                            <li class="li-name">
                                <input type="hidden" id="Id" />店铺名称：
                            </li>
                            <li class="li-input">
                                <input type="text" style="width:161px;" id="name" name="name" placeholder="店铺名称" />
                            </li>
                            <li class="li-name" style="text-align:right;">电话：</li>
                            <li class="li-input">
                                <input placeholder="联系电话" type="text" name="tel" id="tel" style="width:161px;" />
                            </li>
                            <li class="li-name">
                                所在省市：
                            </li>
                            <li class="li-input2">
                                <select style="width: 80px; height: 24px;color: #000; " name="Province" id="Province" class="prov" onchange="set_city(this, document.getElementById('city'));">
                                    <option value="0">请选择</option>
                                    <option value="北京">北京</option>
                                    <option value="上海">上海</option>
                                    <option value="天津">天津</option>
                                    <option value="重庆">重庆</option>
                                    <option value="河北省">河北省</option>
                                    <option value="山西省">山西省</option>
                                    <option value="辽宁省">辽宁省</option>
                                    <option value="吉林省">吉林省</option>
                                    <option value="黑龙江省">黑龙江省</option>
                                    <option value="江苏省">江苏省</option>
                                    <option value="浙江省">浙江省</option>
                                    <option value="安徽省">安徽省</option>
                                    <option value="福建省">福建省</option>
                                    <option value="江西省">江西省</option>
                                    <option value="山东省">山东省</option>
                                    <option value="河南省">河南省</option>
                                    <option value="湖北省">湖北省</option>
                                    <option value="湖南省">湖南省</option>
                                    <option value="广东省">广东省</option>
                                    <option value="海南省">海南省</option>
                                    <option value="四川省">四川省</option>
                                    <option value="贵州省">贵州省</option>
                                    <option value="云南省">云南省</option>
                                    <option value="陕西省">陕西省</option>
                                    <option value="甘肃省">甘肃省</option>
                                    <option value="青海省">青海省</option>
                                    <option value="内蒙古">内蒙古</option>
                                    <option value="广西">广西</option>
                                    <option value="西藏">西藏</option>
                                    <option value="宁夏">宁夏</option>
                                    <option value="新疆">新疆</option>
                                    <option value="香港">香港</option>
                                    <option value="澳门">澳门</option>
                                    <option value="台湾">台湾</option>
                                </select>
                            </li>
                            <li class="li-input3">
                                <select class="city" style="width: 80px; height: 24px;color: #000; " name="City" id="city" onchange="citychange(this);">
                                    <option value="">请选择</option>
                                </select>
                            </li>
                            <li class="li-name" style="text-align:right;">
                                详细地址：
                            </li>
                            <li class="li-input">
                                <div class="divaddress">
                                    <textarea id="address" style="width: 130px; height: 40px;border: none;" name="address" title="详细地址，填完点击“搜索地址”查看地址在地图上的位置是否正确" placeholder="详细地址，具体到街道门牌号"></textarea><img src="http://res.70c.com/scene-editor/images/suo.png" onclick="addressSearch();" />
                                </div>
                            </li>
                            <li style="padding-left: 20px;padding-top: 20px;">
                                <div>
                                    <input type="button" onclick="submitForm();" class="sub" value="添加" id="btnsave" />  <input type="reset" style="margin-left: 10px;" class="sub" value="店铺列表" id="reset" onclick="resetForm();" />  <input type="hidden" name="longitude" id="lng" value="" />
                                    <input type="hidden" name="latitude" id="lat" value="" />
                                </div>
                            </li>
                        </ul>

                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
<script language="javascript">

    var cities = new Object();
    cities['台湾'] = new Array('台北', '高雄', '台中', '台南', '新北', '基隆', '新竹', '嘉义');
    cities['北京'] = new Array('北京');
    cities['上海'] = new Array('上海');
    cities['天津'] = new Array('天津');
    cities['重庆'] = new Array('重庆');
    cities['河北省'] = new Array('石家庄', '保定', '沧州', '承德', '邯郸', '衡水', '廊坊', '秦皇岛', '唐山', '邢台', '张家口');
    cities['山西省'] = new Array('太原', '长治', '大同', '晋城', '晋中', '临汾', '吕梁', '朔州', '忻州', '阳泉', '运城');
    cities['辽宁省'] = new Array('沈阳', '鞍山', '本溪', '朝阳', '大连', '丹东', '抚顺', '阜新', '葫芦岛', '锦州', '辽阳', '盘锦', '铁岭', '营口');
    cities['吉林省'] = new Array('长春', '白城', '白山', '吉林市', '辽源', '四平', '松原', '通化', '延边');
    cities['黑龙江省'] = new Array('哈尔滨', '大庆', '大兴安岭地区', '鹤岗', '黑河', '鸡西', '佳木斯', '牡丹江', '七台河', '齐齐哈尔', '双鸭山', '绥化', '伊春');
    cities['江苏省'] = new Array('南京', '常州', '淮安', '连云港', '南通', '苏州', '宿迁', '泰州', '无锡', '徐州', '盐城', '扬州', '镇江');
    cities['浙江省'] = new Array('杭州', '湖州', '嘉兴', '金华', '丽水', '宁波', '衢州', '绍兴', '台州', '温州', '舟山');
    cities['安徽省'] = new Array('合肥', '安庆', '蚌埠', '亳州', '巢湖', '池州', '滁州', '阜阳', '淮北', '淮南', '黄山', '六安', '马鞍山', '宿州', '铜陵', '芜湖', '宣城');
    cities['福建省'] = new Array('福州', '龙岩', '南平', '宁德', '莆田', '泉州', '三明', '厦门', '漳州');
    cities['江西省'] = new Array('南昌', '抚州', '赣州', '吉安', '景德镇', '九江', '萍乡', '上饶', '新余', '宜春', '鹰潭');
    cities['山东省'] = new Array('济南', '滨州', '东营', '德州', '菏泽', '济宁', '莱芜', '聊城', '临沂', '青岛', '日照', '泰安', '威海', '潍坊', '烟台', '枣庄', '淄博');
    cities['河南省'] = new Array('郑州', '安阳', '鹤壁', '焦作', '开封', '洛阳', '漯河', '南阳', '平顶山', '濮阳', '三门峡', '商丘', '新乡', '信阳', '许昌', '周口', '驻马店');
    cities['湖北省'] = new Array('武汉', '鄂州', '恩施', '黄冈', '黄石', '荆门', '荆州', '潜江', '神农架林区', '十堰', '随州', '天门', '仙桃', '咸宁', '襄阳', '孝感', '宜昌');
    cities['湖南省'] = new Array('长沙', '常德', '郴州', '衡阳', '怀化', '娄底', '邵阳', '湘潭', '湘西州', '益阳', '永州', '岳阳', '张家界', '株洲');
    cities['广东省'] = new Array('广州', '潮州', '东莞', '佛山', '河源', '惠州', '江门', '揭阳', '茂名', '梅州', '清远', '汕头', '汕尾', '韶关', '深圳', '阳江', '云浮', '湛江', '肇庆', '中山', '珠海');
    cities['海南省'] = new Array('海口', '白沙', '保亭', '昌江', '儋州', '澄迈', '东方', '定安', '琼海', '琼中', '乐东', '临高', '陵水', '三亚', '屯昌', '万宁', '文昌', '五指山');
    cities['四川省'] = new Array('成都', '阿坝州', '巴中', '达州', '德阳', '甘孜州', '广安', '广元', '乐山', '凉山州', '泸州', '南充', '眉山', '绵阳', '内江', '攀枝花', '遂宁', '雅安', '宜宾', '资阳', '自贡');
    cities['贵州省'] = new Array('贵阳', '安顺', '毕节地区', '六盘水', '铜仁地区', '遵义', '黔西南州', '黔东南州', '黔南州');
    cities['云南省'] = new Array('昆明', '保山', '楚雄州', '大理州', '德宏州', '迪庆州', '红河州', '丽江', '临沧', '怒江州', '普洱', '曲靖', '昭通', '文山', '西双版纳', '玉溪');
    cities['陕西省'] = new Array('西安', '安康', '宝鸡', '汉中', '商洛', '铜川', '渭南', '咸阳', '延安', '榆林');
    cities['甘肃省'] = new Array('兰州', '白银', '定西', '甘南州', '嘉峪关', '金昌', '酒泉', '临夏州', '陇南', '平凉', '庆阳', '天水', '武威', '张掖');
    cities['青海省'] = new Array('西宁', '果洛州', '海东地区', '海北州', '海南州', '海西州', '黄南州', '玉树州');
    cities['内蒙古'] = new Array('呼和浩特', '阿拉善盟', '包头', '巴彦淖尔', '赤峰', '鄂尔多斯', '呼伦贝尔', '通辽', '乌海', '乌兰察布', '锡林郭勒盟', '兴安盟');
    cities['广西'] = new Array('南宁', '百色', '北海', '崇左', '防城港', '桂林', '贵港', '河池', '贺州', '来宾', '柳州', '钦州', '梧州', '玉林');
    cities['西藏'] = new Array('拉萨', '阿里地区', '昌都地区', '林芝地区', '那曲地区', '日喀则地区', '山南地区');
    cities['宁夏'] = new Array('银川', '固原', '石嘴山', '吴忠', '中卫');
    cities['新疆'] = new Array('乌鲁木齐', '阿拉尔', '阿克苏地区', '阿勒泰地区', '巴音郭楞', '博尔塔拉州', '昌吉州', '哈密地区', '和田地区', '喀什地区', '克拉玛依', '克孜勒苏州', '石河子', '塔城地区', '图木舒克', '吐鲁番地区', '五家渠', '伊犁州');
    cities['香港'] = new Array('香港');
    cities['澳门'] = new Array('澳门');

    function set_city(province, city) {
        var pv, cv;
        var i, ii;
        pv = province.value;
        cv = city.value;
        city.length = 1;
        if (pv == '0') return;
        if (typeof (cities[pv]) == 'undefined') return;
        for (i = 0; i < cities[pv].length; i++) {
            ii = i + 1;
            city.options[ii] = new Option();
            city.options[ii].text = cities[pv][i];
            city.options[ii].value = cities[pv][i];
        }
        if (cities[pv].length == 1) {
            city.value = cities[pv][0];
            cityName = cities[pv][0];
            map.setCenter(cityName);
        }
    }

    function showNone(event) {
        var evt = event || window.event;
        $(evt.target).find(".edit").hide();
    }
    function showBlock(event) {
        var evt = event || window.event;
        $(evt.target).find(".edit").show();
    }

    function checkall() {
        var chkallchked = document.getElementById("allcheck").checked;
        var chk = document.getElementsByName("chk");
        for (var i = 0; i < chk.length; i++) {
            chk[i].checked = chkallchked;
        }
    }
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    };
    if (GetQueryString("tab") == "list" || document.getElementById("addressCount").value != 0) {
        resetForm();
    } else {
        addmapdata();
    }
    window.parent.document.getElementById('divditu_footer').style.display = "none";
    function editmap(Id, Name, Tel, Province, City, Address, lat, lng) {
        document.getElementById("maplist").style.display = "none";
        document.getElementById("mapedit").style.display = "block";
        window.parent.document.getElementById('divditu_footer').style.display = "none";

        document.getElementById("tel").value = Tel;
        document.getElementById("address").value = Address;
        document.getElementById("Province").value = Province;
        set_city(document.getElementById("Province"), document.getElementById("city"));
        document.getElementById("city").value = City;
        // map.setCenter(City);

        document.getElementById("name").value = Name;
        document.getElementById("Id").value = Id;
        document.getElementById("btnsave").value = "保存";

        addressSearch(lat, lng);
    }
    function addmapdata() {
        document.getElementById("mapedit").style.display = "block";
        document.getElementById("maplist").style.display = "none";
        window.parent.document.getElementById('divditu_footer').style.display = "none";
        //divditu_footer
    }
    function resetForm() {
        document.getElementById("btnsave").value = "添加";
        document.getElementById("mapedit").style.display = "none";
        document.getElementById("maplist").style.display = "block";
        // window.parent.document.getElementById('divditu_footer').style.display = "block";
    }
    function addressDels() {
        if (confirm("是否确定删除？")) {
            var chks = document.getElementsByName("chk");
            var ids = "";
            for (var i = 0; i < chks.length; i++) {
                if (chks[i].checked) {
                    ids += chks[i].value + ",";
                }
            }
            if (ids == "") {
                alertfun("请至少选择一个要删除的地址。");
                return false;
            }
            var url = "/map/delmaps?ids=" + ids + "&sceneid=" + SceneID;
            var fun = function (data) {
                if (data.indexOf("true") > 0) {
                    alertfun("删除成功")
                    location.reload();

                } else {
                    alertfun("删除失败");
                }
            }
            ajaxGet(url, fun);
        }
    }
    function delmap(id) {
        if (confirm("是否确定删除？")) {
            var url = "/map/delmap?id=" + id + "&sceneid=" + SceneID;
            var fun = function (data) {
                if (data.indexOf("true") > 0) {
                    alertfun("删除成功");
                    location.reload();
                } else {
                    alertfun("删除失败");
                }
            }
            ajaxGet(url, fun);
        }
    }
    function ajaxGet(url, fun) {
        var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        req.onreadystatechange = function () {
            if (req.readyState == 4) {
                fun(req.responseText);
            }
        };
        req.open("GET", url, "false");
        req.send(null);
    }
    var Latitude = "";
    var Longitude = "";
    function submitForm() {
        var savetype = document.getElementById("btnsave").value;
        if (Latitude == "") {
            Latitude = document.getElementById("lat").value;
        }
        if (Longitude == "") {
            Longitude = document.getElementById("lng").value;
        }
        if (!Latitude) {
            alertfun("请先点击“搜索地址”给位置标注");
            return false;
        }
        var tel = document.getElementById("tel").value;
        if (!(/^(\d{10,11})|^((\d{7,8})|^(\d{5})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/.test(tel))) {
            alertfun("电话号码格式不正确");

            document.getElementById("tel").focus();
            return false;
        }

        var address = document.getElementById("address").value;
        var province = document.getElementById("Province").value;
        var city = document.getElementById("city").value;
        var name = document.getElementById("name").value;
        var sceneID = GetQueryString("sceneID");
        var param = "tel=" + tel + "&address=" + encodeURIComponent(address) + "&province=" + encodeURIComponent(province) + "&city=" + encodeURIComponent(city) + "&name=" + encodeURIComponent(name) + "&sceneID=" + sceneID + "&Latitude=" + Latitude + "&Longitude=" + Longitude;
        var url = "/map/mapdatasave?" + param;
        if (savetype == "保存") {
            //编辑保存
            var id = document.getElementById("Id").value;
            url = "/map/mapdateedit?" + param + "&Id=" + id;
        }
        var fun = function (ret) {
            if (ret.indexOf('true') > 0) {
                alertfun("保存成功！");


                /*if(window.confirm("保存成功，点击确定继续添加,查看全部点击取消。")){
                    var url = location.href;
                    if (url.indexOf("city=") == -1) {
                        url = location.href + "&city=" + escape(city)
                    } else {
                        url = url.split("?")[0] + "?SceneID=" + sceneID + "&city=" + escape(city);
                    }
                    location.href = url;
                   // window.parent.document.getElementById('divditu_footer').style.display = "block";
                }else{   */
                location.href = location.href + "&tab=list";
                //location.reload();
                // }
            } else {
                alertfun("对不起，保存失败，请联系管理员。");

                return false;
            }
        }
        ajaxGet(url, fun);
    }
    function alertfun(txt) {
        $("#successTip").text(txt).animate({ opacity: '1' }, 10);
        $("#successTip").text(txt).animate({ opacity: '0' }, 6000);
    }

    // 百度地图API功能
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(116.391398, 39.897445);
    map.centerAndZoom(point, 11);
    //鼠标滚轮缩放
    map.enableScrollWheelZoom(true);
    var top_right_navigation = new BMap.NavigationControl();
    map.addControl(top_right_navigation);       // 添加平移缩放控件
    map.addControl(new BMap.ScaleControl());            // 添加比例尺控件
    map.addControl(new BMap.OverviewMapControl());      // 添加缩略地图控件
    map.enableAutoResize();

    var cityName = GetQueryString("city");
    if (!!cityName) {
        map.setCenter(cityName);
    } else {
        function myFun(result) {
            cityName = result.name;
            // map.setCenter(cityName);
            point = new BMap.Point(result.center.lng, result.center.lat);
            map.centerAndZoom(point, 11);
        }
        //IP定位获取当前城市
        var myCity = new BMap.LocalCity();
        myCity.get(myFun);
    }

    var adds = [];

    var lng = document.getElementById("lng").value;
    var lat = document.getElementById("lat").value;
    if (lng != '' && lat != '') {
        point = new BMap.Point(lng, lat);
        zoom = 14
    }

    var marker = new BMap.Marker(point);
    map.addOverlay(marker);
    map.addEventListener("click", function (e) {
        changeMarker(e);
    });

    //清空屏幕上的标记，并重新添加一个标记
    function changeMarker(e) {
        coord = new Array(e.point.lng, e.point.lat);
        map.clearOverlays();
        point = new BMap.Point(e.point.lng, e.point.lat);
        marker = new BMap.Marker(point);
        map.addOverlay(marker);
        document.getElementById("lng").value = e.point.lng;
        document.getElementById("lat").value = e.point.lat;
        // 根据坐标得到地址描述
        myGeo.getLocation(new BMap.Point(e.point.lng, e.point.lat), function (result) {
            if (result) {

                var ptemp = result.addressComponents.province;
                document.getElementById("Province").value = ptemp.replace("市", "");
                set_city(document.getElementById("Province"), document.getElementById("city"));
                var ctemp = result.addressComponents.city;
                document.getElementById("city").value = ctemp.replace("市", "").replace("地区", "");
                var atemp = result.address;
                document.getElementById("address").value = atemp.replace(ptemp, "").replace(ctemp, "");
            }
        });
    }

    //根据地图上的当前标记对象，清空屏幕上的标记，并重新添加一个标记
    function changeMarkerByMark(e) {
        map.removeOverlay(marker);
        point = new BMap.Point(e.target.getPosition());
        marker = new BMap.Marker(point);
        map.addOverlay(marker);
        document.getElementById("lng").value = e.target.getPosition().lng;
        document.getElementById("lat").value = e.target.getPosition().lat;
        // 根据坐标得到地址描述
        myGeo.getLocation(new BMap.Point(e.target.getPosition().lng, e.target.getPosition().lat), function (result) {
            if (result) {
                var ptemp = result.addressComponents.province;
                document.getElementById("Province").value = ptemp.replace("市", "");
                set_city(document.getElementById("Province"), document.getElementById("city"));
                var ctemp = result.addressComponents.city;
                document.getElementById("city").value = ctemp.replace("市", "").replace("地区", "");
                var atemp = result.address;
                document.getElementById("address").value = atemp.replace(ptemp, "").replace(ctemp, "");
            }
        });
    }

    var m = [];
    var local = new BMap.LocalSearch(map, {
        renderOptions: { map: map }, //panel :'search_list'},
        onMarkersSet: function (results) {
            if (local.getStatus() == BMAP_STATUS_SUCCESS) {
                m = [];
                for (var i in results) {
                    m[i] = results[i].marker;
                    m[i].addEventListener('infowindowopen', function (e) {
                        changeMarkerByMark(e);
                    });
                }
            }
        }
    });


    function citychange(city) {
        cityName = city.value;
        map.setCenter(cityName);
        Latitude = "";
        Longitude = "";
    }

    var SceneID = GetQueryString("sceneID");
    function myFun(result) {
        cityName = result.name;
        map.setCenter(cityName);
        //获取指定城市的网点
        //document.getElementById("curCity").innerHTML = cityName;
        var city = encodeURIComponent(cityName);
        var url = "/As/getAddressEdit?sceneid=" + SceneID + "&city=" + city;
        var fun = function (ret) {
            if (!ret) {
                // alertfun("对不起，当前城市没有网点。");
                return false;
            }
            adds = ret.split('$');
            bdGEO();
        }
        ajaxGet(url, fun);
    }


    //IP定位获取当前城市
    // var myCity = new BMap.LocalCity();
    // myCity.get(myFun);

    ///////////批量地址解析
    var index = 0;
    var myGeo = new BMap.Geocoder();

    function addressSearch(lat, lng) {
        var add = document.getElementById("address").value;
        var city = document.getElementById("city").value;
        if (!city) {
            alertfun("请先选择省份和城市。");
            return false;
        }
        if (!add) {
            alertfun("请先输入详细地址。");
            return false;
        }

        // 根据确切的经纬度来定位
        if (lat && lng) {
            setTimeout(function () {
                var point = new BMap.Point(lng, lat);
                map.centerAndZoom(point, 16);
                map.addOverlay(new BMap.Marker(point));
            }, 200);
            document.getElementById("lat").value = lat;
            document.getElementById("lng").value = lng;
        } else { // 根据地名来定位
            // 将地址解析结果显示在地图上,并调整地图视野
            myGeo.getPoint(add, function (point) {
                if (point) {
                    map.centerAndZoom(point, 16);
                    map.addOverlay(new BMap.Marker(point));
                    Latitude = point.lat;
                    document.getElementById("lat").value = Latitude;
                    Longitude = point.lng;
                    document.getElementById("lng").value = Longitude;
                } else {
                    alertfun("您选择地址没有解析到结果!");
                }
            }, city);
        }
    }
    function bdGEO() {
        var add = adds[index];
        !!add && geocodeSearch(add);
        index++;
    }

    function geocodeSearch(fullAdd) {
        if (index < adds.length) {
            setTimeout(window.bdGEO, 400);
        }

        var add = fullAdd.split('#')[0];
        // 召陵区燕山路(111)#电话：1234567#33.565124,114.086121
        // 地址(店铺名)#电话：xxx#lat,lng
        // 根据经纬度来定位店铺
        var latlng = fullAdd.split('#')[2];
        if (latlng) {
            latlng = latlng.split(',');
            var address = new BMap.Point(latlng[1], latlng[0]);
            addMarker(address, add);
        } else {
            myGeo.getPoint(add, function (point) {
                if (point) {
                    var address = new BMap.Point(point.lng, point.lat);
                    addMarker(address, add);
                }
            }, cityName);
        }
    }
    // 编写自定义函数,创建标注
    function addMarker(point, content) {
        var marker1 = new BMap.Marker(point);
        map.addOverlay(marker1);
        addClickHandler(content, marker1);
    }
    function addClickHandler(content, marker) {
        marker.addEventListener("click", function (e) {
            openInfo(content, e)
        }
    );
    }
    var opts = {
        width: 250,     // 信息窗口宽度
        height: 90,     // 信息窗口高度
        enableMessage: false,
        title: "信息窗口"
    };
    function openInfo(content, e) {
        var p = e.target;
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        opts.title = content.split("(")[1].split(")")[0];
        var address = content.split("(")[0];
        var tel = getTel(content);
        var infoWindow = new BMap.InfoWindow("地址：" + address + tel, opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow, point); //开启信息窗口
    }
    function getTel(content) {
        var tel = "";
        for (var i = 0; i < adds.length; i++) {
            if (adds[i].indexOf(content) > -1) {
                if (adds[i].split("#").length > 0) {
                    tel = "\n\t<br/>" + adds[i].split("#")[1];
                }
            }
        }
        return tel;
    }


</script>
</html>


